 package com.oanda.blackberry.restapi;
 
 import com.oanda.blackberry.util.log.Logger;
 
 public class TradeOrder
 {
   String symbol;
   int units;
   double rate;
   String accountid;
   String type;
   double lowerPrice;
   double highPrice;
   double stopLoss;
   double takeProfit;
   double trailingStop;
   String tradeType;
   double pipLoc;
 
   public TradeOrder()
   {
   }
 
   public TradeOrder(String symbol, int units, String accountid, String type, double rate, double lowerPrice, double highPrice, double stopLoss, double takeProfit, double trailingStop, String tradeType, double pipLoc)
   {
     this.symbol = symbol;
     this.units = units;
     this.rate = rate;
     this.accountid = accountid;
     this.type = type;
     this.lowerPrice = lowerPrice;
     this.highPrice = highPrice;
     this.stopLoss = stopLoss;
     this.takeProfit = takeProfit;
     this.trailingStop = trailingStop;
     this.tradeType = tradeType;
     this.pipLoc = pipLoc;
   }
 
   public String validate()
   {
     String error = "";
 
     if (this.units <= 0) error = "Error: Units must be greater than 0";
     if (this.rate <= 0.0D) error = "invalid quote";
     if ((this.lowerPrice != (0.0D / 0.0D)) && ((this.lowerPrice < 0.0D) || (this.lowerPrice > this.rate))) error = "Error: trade below limit";
     if ((this.highPrice != (0.0D / 0.0D)) && ((this.highPrice <= 0.0D) || (this.highPrice < this.rate))) error = "Error: trade above limit";
 
     if ((this.takeProfit != (0.0D / 0.0D)) && (this.takeProfit <= 0.0D)) error = "invalid take profit";
     if ((this.takeProfit != (0.0D / 0.0D)) && (this.tradeType.equals("long")) && (this.takeProfit < this.rate)) error = "Error: Take Profit price of " + this.takeProfit + " must be above current ask price of " + this.rate;
     if ((this.takeProfit != (0.0D / 0.0D)) && (this.tradeType.equals("short")) && (this.takeProfit > this.rate)) error = "Error: Take Profit price of " + this.takeProfit + " must be below current bid price of " + this.rate;
 
     if ((this.stopLoss != (0.0D / 0.0D)) && (this.stopLoss <= 0.0D)) error = "invalid stop loss";
     if ((this.stopLoss != (0.0D / 0.0D)) && (this.tradeType.equals("long")) && (this.stopLoss > this.rate)) error = "Error: Stop Loss price of " + this.stopLoss + " must be below current bid price of " + this.rate;
     if ((this.stopLoss != (0.0D / 0.0D)) && (this.tradeType.equals("short")) && (this.stopLoss < this.rate)) error = "Error: Stop Loss price of " + this.stopLoss + " must be above current ask price of " + this.rate;
 
     Logger.log("validating ts: " + String.valueOf(this.trailingStop) + " tradeType: " + this.tradeType);
 
     if ((this.trailingStop != (0.0D / 0.0D)) && (this.trailingStop <= 0.0D)) {
       error = "Error: Trailng Stop must be at least 10 pips";
     }
 
     if (((!this.symbol.equalsIgnoreCase("xau/usd")) || (!this.symbol.equalsIgnoreCase("xag/usd"))) && (this.units > 10000000)) error = "invalid units";
     if ((this.symbol.equalsIgnoreCase("xau/usd")) && (this.units > 5000)) error = "invalid units (5000 max)";
     if ((this.symbol.equalsIgnoreCase("xag/usd")) && (this.units > 100000)) error = "invalid units (100,000 max)";
     return error;
   }
 
   public String getAccountid() {
     return this.accountid;
   }
 
   public double getHighPrice() {
     return this.highPrice;
   }
 
   public double getLowerPrice() {
     return this.lowerPrice;
   }
 
   public double getPipLoc() {
     return this.pipLoc;
   }
 
   public double getRate() {
     return this.rate;
   }
 
   public double getStopLoss() {
     return this.stopLoss;
   }
 
   public String getSymbol() {
     return this.symbol;
   }
 
   public double getTakeProfit() {
     return this.takeProfit;
   }
 
   public String getTradeType() {
     return this.tradeType;
   }
 
   public double getTrailingStop() {
     return this.trailingStop;
   }
 
   public String getType() {
     return this.type;
   }
 
   public int getUnits() {
     return this.units;
   }
}

